import request from '@/config/axios'

// 试题 VO
export interface QuestionVO {
  id: number // 主键
  bankId: number // 题库
  type: number // 类型
  title: string // 题干
  content: string // 内容
  markType: number //  阅卷类型
  markOptions: string //  阅卷选项
  analysis: string // 解析
  score: number // 默认分值
  state: number // 状态
  difficulty: number // 难度
  chapter: number // 章节
  label: string // 知识点, 多个逗号隔开
}

// 试题-选项 VO
export interface QuestionOptionsVO {
  id: number // 主键
  questionId: number // 题库
  options: number // 类型
  content: string // 题干
  no: string // 内容
}
// 试题-答案 VO
export interface QuestionAnswerVO {
  selected: string ,// 单选答案
  selectedList: string ,// 单选答案
  fill: [string] ,// 填空答案
}
export interface CodeQuestionVO extends QuestionVO {
  options: [QuestionOptionsVO]
  memberAnswer: QuestionAnswerVO
}

// 试题 API
export const QuestionApi = {
  // 查询试题分页
  getQuestionPage: async (params: any) => {
    return await request.get({ url: `/exam/question/page`, params })
  },

  // 查询试题详情
  getQuestion: async (id: number) => {
    return await request.get({ url: `/exam/question/get?id=` + id })
  },

  // 新增试题
  createQuestion: async (data: QuestionVO) => {
    return await request.post({ url: `/exam/question/create`, data })
  },

  // 修改试题
  updateQuestion: async (data: QuestionVO) => {
    return await request.put({ url: `/exam/question/update`, data })
  },

  // 删除试题
  deleteQuestion: async (id: number) => {
    return await request.delete({ url: `/exam/question/delete?id=` + id })
  },

  // 导出试题 Excel
  exportQuestion: async (params) => {
    return await request.download({ url: `/exam/question/export-excel`, params })
  },

// ==================== 子表（试题答案） ====================

  // 获得试题答案列表
  getQuestionAnswerListByQuestionId: async (questionId) => {
    return await request.get({ url: `/exam/question/question-answer/list-by-question-id?questionId=` + questionId })
  },

// ==================== 子表（试题选项） ====================

  // 获得试题选项列表
  getQuestionOptionListByQuestionId: async (questionId) => {
    return await request.get({ url: `/exam/question/question-option/list-by-question-id?questionId=` + questionId })
  }
}
